<HTML>
<HEAD>
<TITLE>[Chapter 19] TextComponent</TITLE>
<META NAME="author" CONTENT="John Zukowski">
<META NAME="date" CONTENT="Thu Jul 31 15:16:31 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java AWT">
<META NAME="title" CONTENT="Java AWT">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java AWT" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_57.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 19<br>java.awt Reference</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch19_59.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<DIV CLASS=refnamediv>
<H1>TextComponent</H1>

<H2>Name</H2>

TextComponent

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="ch19-REFSECT1-AUTOID.58"></A></h2>
</DIV>


<p>
<img align=middle src="./figs/textco2.gif" alt="[Graphic: Figure from the text]" width=502 height=113 border=0>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-1">Description</A></h2>

<P CLASS=para>
The abstract <tt CLASS=literal>TextComponent</tt> 
class provides the base class for the text input components, <tt CLASS=literal>TextArea</tt> 
and <tt CLASS=literal>TextField</tt>. 

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-2">Class Definition</A></h2>

<DIV CLASS=screen>
<P>
<PRE>
public abstract class java.awt.TextComponent
    extends java.awt.Component {
  
  // Instance Methods
  public void addTextListener (TextListener l); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public int getCaretPosition(); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public synchronized String getSelectedText();
  public synchronized int getSelectionEnd();
  public synchronized int getSelectionStart();
  public synchronized String getText();
  public boolean isEditable();
  public void removeNotify();
  public void removeTextListener (TextListener l); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public synchronized void select (int selectionStart, int selectionEnd);
  public synchronized void selectAll();
  public void setCaretPosition (int position); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public synchronized void setEditable (boolean state);
  public synchronized void setSelectionEnd (int selectionEnd); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public synchronized void setSelectionStart (int selectionStart); <img src="gifs/bstar.gif" alt="(New)" border=0>
  public synchronized void setText (String text);
  
  // Protected Instance Methods
  protected String paramString();
  protected void processEvent (AWTEvent e); <img src="gifs/bstar.gif" alt="(New)" border=0>
  protected void processTextEvent (TextEvent e); <img src="gifs/bstar.gif" alt="(New)" border=0>
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3">Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.1">addTextListener</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.1.1">public void addTextListener (TextListener l) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>l</I><br>
<DD>

<P CLASS=para>
An object that implements the <tt CLASS=literal>TextListener</tt> 
interface. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Add a listener for the text events. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.2">getCaretPosition</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.2.1">public int getCaretPosition() <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The position, in characters, of the caret (text cursor). </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.3">getSelectedText</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.3.1">public synchronized String getSelectedText()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The currently selected text of the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.4">getSelectionEnd</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.4.1">public synchronized int getSelectionEnd()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The ending cursor position of any selected text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.5">getSelectionStart</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.5.1">public synchronized int getSelectionStart()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
The initial position of any selected text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.6">getText</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.6.1">public synchronized String getText()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
Current contents of the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.7">isEditable</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.7.1">public boolean isEditable()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
<tt CLASS=literal>true</tt> if editable, <tt CLASS=literal>false</tt> 
otherwise. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.8">removeNotify</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.8.1">public void removeNotify()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Destroys the peer of the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.9">removeTextListener</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.9.1">public void removeTextListener (TextListener l) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>l</I><br>
<DD>

<P CLASS=para>
One of this <tt CLASS=literal>TextComponent</tt>'s 
<tt CLASS=literal>TextListener</tt>s. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Remove a text event listener. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.10">select</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.10.1">public synchronized void select (int selectionStart, int selectionEnd)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>selectionStart</I><br>
<DD>

<P CLASS=para>
Beginning position of text to select. 

<p>
<DT CLASS=varlistentry><I CLASS=emphasis>selectionEnd</I><br>
<DD>

<P CLASS=para>
Ending position of text to select. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Selects text in the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.11">selectAll</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.11.1">public synchronized void selectAll()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Selects all the text in the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.12">setCaretPosition</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.12.1">public void setCaretPosition (int position) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>position</I><br>
<DD>

<P CLASS=para>
The new character position for the caret. </DL>
<p>
<DT CLASS=varlistentry>Throws <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>IllegalArgumentException</I><br>
<DD>

<P CLASS=para>
If 
<tt CLASS=literal>position</tt> is less than zero. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Allows you to change the location of the caret. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.13">setEditable</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.13.1">public synchronized void setEditable (boolean state)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>state</I><br>
<DD>

<P CLASS=para>
<tt CLASS=literal>true</tt> to allow 
the user to edit the text in the <tt CLASS=literal>TextComponent</tt>; 
<tt CLASS=literal>false</tt> to prevent editing. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Allows you to make the <tt CLASS=literal>TextComponent</tt> 
editable or read-only. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.14">setSelectionEnd</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.14.1">public synchronized void setSelectionEnd (int selectionEnd) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>selectionEnd</I><br>
<DD>

<P CLASS=para>
The character position of the end of the selection. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Allows you to change the location of the end of the selected text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.15">setSelectionStart</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.15.1">public synchronized void setSelectionStart (int selectionStart) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>selectionStart</I><br>
<DD>

<P CLASS=para>
The character position of the start of the selection. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Allows you to change the location of the start of the selected text. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.16">setText</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-3.16.1">public synchronized void setText (String text)</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>text</I><br>
<DD>

<P CLASS=para>
New text for <tt CLASS=literal>TextComponent</tt>. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Sets the content of the <tt CLASS=literal>TextComponent</tt>. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4">Protected Instance Methods</A></h2>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.1">paramString</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.1.1">protected String paramString()</A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Returns<br>
<DD>

<P CLASS=para>
String with current settings of <tt CLASS=literal>TextComponent</tt>. 

<p>
<DT CLASS=varlistentry>Overrides <br>
<DD>

<P CLASS=para>
<tt CLASS=literal>Component.paramString()</tt> 

<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Helper method for <tt CLASS=literal>toString()</tt> 
to generate string of current settings. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.2">processEvent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.2.1">protected void processEvent (AWTEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>e</I><br>
<DD>

<P CLASS=para>
The event to process. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Low-level <tt CLASS=literal>AWTEvent</tt>s are passed 
to this method for processing. </DL>
</DIV>

</DIV>

<DIV CLASS=refsect2>
<h3 CLASS=refsect2><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.3">processTextEvent</A></h3>

<DIV CLASS=refsect3>
<h4 CLASS=refsect3><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-4.3.1">protected void processTextEvent (TextEvent e) <img src="gifs/bstar.gif" alt="(New)" border=0></A></h4>

<DL CLASS=variablelist>
<DT CLASS=varlistentry>Parameters <br>
<DD>

<P>
<DL CLASS=variablelist>
<DT CLASS=varlistentry><I CLASS=emphasis>e</I><br>
<DD>

<P CLASS=para>
The event to process. </DL>
<p>
<DT CLASS=varlistentry>Description<br>
<DD>

<P CLASS=para>
Text events are passed to this method for processing. Normally, this method 
is called by <tt CLASS=literal>processEvent()</tt>. </DL>
</DIV>

</DIV>

</DIV>

<DIV CLASS=refsect1>
<h2 CLASS=refsect1><A CLASS="TITLE" NAME="JAWT-CH-19-REF-TEXTCOMPONENT-SECT-5">See Also</A></h2>

<P CLASS=para>
<tt CLASS=literal>Component</tt>, <tt CLASS=literal>TextArea</tt>, 
<tt CLASS=literal>TextField</tt>, <tt CLASS=literal>String</tt> 

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch19_57.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch19_59.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>TextArea</td>
<td width=171 align=center valign=top><a href="index/idx_a.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>TextField</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
